package org.xxmi.cors.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xxmi.cors.configurations.WebSocketServer;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/web-socket")
public class WebSocketController {


    @Autowired
    private SimpMessagingTemplate temp;


    @RequestMapping("/push/{toUserId}")
    @PostMapping
    public ResponseEntity<String> pushToWeb(@PathVariable String toUserId, String message) throws IOException {
//        WebSocketServer.sendInfo(message, toUserId);
        temp.convertAndSend("topic/" + toUserId, message);
        return ResponseEntity.ok("消息发送成功");
    }


}
